/*
 * CastDRAndroid
 * Copyright (c) 2014 Christian Holm Christensen
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 *
 */
package org.cholm.media.castdr.backend;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

// import org.json.JSONException;

/**
 * @author cholm
 */
public class Serie {
    /**
     * Our slug
     */
    protected String mSlug = null;
    /**
     * Our title
     */
    protected String mTitle = null;
    /**
     * Presentation URL
     */
    protected String mUrl = null;
    /**
     * Genre
     */
    protected String mGenre = null;
    /**
     * Channel
     */
    protected String mChannel = null;
    /**
     * Image url
     */
    protected String mImg = null;
    /**
     * First letter
     */
    protected String mLetter = null;
    /**
     * List of videos
     */
    protected List<Program> mPrograms = new ArrayList<Program>();

    /**
     * Constructor
     *
     * @param json JSON data
     * @throws Exception On error
     */
    public Serie(JSONObject data0) {
        mTitle = data0.optString("Title");
        mGenre = data0.optString("OnlineGenreText");
        mUrl = data0.optString("Url");
        mSlug = data0.optString("ProgramSeriesSlug");
        mChannel = Extractor.convChannel(data0.optString("ChannelSlug"));
        mImg = data0.optString("Image");
        if (mSlug != null && !mSlug.isEmpty()) {
            mLetter = Character.toString(mSlug.charAt(0));
            if (!Character.isLetter(mLetter.charAt(0)))
                mLetter = "-";
            else
                mLetter = mLetter.toUpperCase(Extractor.DANISH);
        }
        if (mGenre.isEmpty()) mGenre = "Ingen";
    }

    /**
     * Check if fields are set
     *
     * @return true if the fields are set
     */
    public boolean isValid() {
        return !(mLetter == null || mGenre == null || mSlug == null
                || mChannel == null || mTitle == null);
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return mTitle;
    }

    /**
     * @return the slug
     */
    public String getSlug() {
        return mSlug;
    }

    /**
     * @return the program url
     */
    public String getUrl() {
        return mUrl;
    }

    /**
     * @return the genre
     */
    public String getGenre() {
        return mGenre;
    }

    /**
     * @return the channel
     */
    public String getChannel() {
        return mChannel;
    }

    /**
     * @return Image url
     */
    public String getImage() {
        return mImg;
    }

    /**
     * @return the videos
     */
    public List<Program> getPrograms() {
        return mPrograms;
    }

    /**
     * @return the letter
     */
    public String getLetter() {
        return mLetter;
    }

    public boolean load() {
        if (mPrograms.size() > 0) return true;
        Extractor e = Extractor.instance();
        return e.loadSerie(this, true);
    }

}
//
// EOF
//
